import unittest
import requests
import json
import ddt
import os

from config.setting import data_path, host

from util.RequestsUtil import RequestUtil
from util.excel_handler import ExcelHandler


# host = "https://api.xdclass.net"
# 项目路径
# root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# 测试数据路径
# data_path = os.path.join(root_path,'Excel\cases.xlsx')


def assertEqual(param, param1, param2):
    pass


@ddt.ddt
class IndexTestLogin(unittest.TestCase):

    excel_handler = ExcelHandler(data_path)
    # 把测试数据从Login表读出，存在data中，就可以把data存在ddt中进行读取
    data = excel_handler.read1('Login')
    url = host + "/pub/api/v1/web/web_login"
    headers = {"Content-Type": "application/x-www-form-urlencoded"}

    @ddt.data(*data)
    def testLogin(self,test_data):
        """登录的情况"""
        req =RequestUtil()

        # headers = {"Content-Type": "application/x-www-form-urlencoded"}
        # data = {"phone":"13113777555","pwd":"1234567890"}

        result = req.requesthandler(self.url,'post',param=json.loads(test_data['data']),headers=json.loads(test_data['headers']))

        assertEqual(result['code'],0,"业务不正常")

        # 123
        #222



if __name__ == '__main__':
    unittest.main(verbosity=2)




